$(function () {
    var layer = layui.layer;
    var form = layui.form;
    var laypage = layui.laypage;
    //----------------------------------------------------------------
    //  页面查询参数
    var query = {
        pagenum: 1, //页码值
        pagesize: 5, //每页显示几条数据
        lab_class_name: '', //宿舍管理员
        lab_address: '', //楼栋
    }
    // 渲染分页功能
    function renderPage(total) {
        // console.log(total);
        laypage.render({
            elem: 'pageBox', //分页容器的id
            count: total, //数据总数，从服务端得到
            limit: query.pagesize, //每页显示几条数据
            curr: query.pagenum,
            layout: ["count", "limit", "prev", "page", "next", "skip"],
            limits: [5, 10, 15, 20],
            jump: function (obj, first) {
                // console.log(first);
                query.pagenum = obj.curr;
                query.pagesize = obj.limit;
                // 首行不执行
                if (!first) {
                    initLabList();
                }
            },

        });
    }
    //------------------------------------------------------------------------------
    // 调用渲染宿舍列表信息的函数
    initLabList()
    //------------------------------------------------------------------------------
    // 获取所有宿舍的列表
    function initLabList() {
        var lab_class_name = $('#form_search [name = lab_class_person ]').val()
        var lab_address = $('#form_search [name = lab_address]').val()
        // console.log(lab_class_name);
        // console.log(lab_address);
        query.lab_class_name = lab_class_name;
        query.lab_address = lab_address;
        $.ajax({
            method: 'GET',
            url: '/my/labManage/getListAdmin/',
            data: query,
            success: function (res) {
                // console.log(res);
                var htmStr = template('tpl_lab_list', res);
                $('tbody').html(htmStr)
                renderPage(res.total)
            }
        })
    }
    //----------------------------------------------------------------
    //模糊搜索需要的信息
    $('#form_search').on('submit', function (e) {
        e.preventDefault()
        initLabList();
    })
})